package space.goldchen.mapstruct.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import space.goldchen.mapstruct.dto.PigDto;
import space.goldchen.mapstruct.entity.Pig;
import space.goldchen.mapstruct.mapper.PigDtoMapper;

/**
 * @author 2021
 * @create 2025-04-18 16:58
 */
@RestController
@Slf4j
public class MapstructController {

    @Autowired
    private PigDtoMapper pigDtoMapper;
    /**
     * 测试调用mapstruct
     */
    @RequestMapping("/test")
    public String test() {
        Pig pig = new Pig();
        pig.setId(1L);
        pig.setName("pig");
        pig.setAge(2);
        pig.setPrice(100.0);

        PigDto pigDto = pigDtoMapper.toDto(pig);
        log.info("pigDto:{}", pigDto);


        // dto to entity
        Pig pig1 = pigDtoMapper.toEntity(pigDto);
        log.info("pig1:{}", pig1);

        return "success";
    }
}
